package cn.moukou.sbzz.service;

import cn.moukou.sbzz.mapper.BankMapper;
import cn.moukou.sbzz.mapper.BankProductMapper;
import cn.moukou.sbzz.pojo.BankProduct;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BankProductService {

    @Autowired
    BankProductMapper bankProductMapper;
    @Autowired
    BankMapper bankMapper;

    public int pubOneBankProduct(BankProduct bankProduct) {
        return bankProductMapper.insert(bankProduct);
    }

    public List<BankProduct> getMyBankProduct(String bid) {
        QueryWrapper<BankProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("bid", bid);
        return bankProductMapper.selectList(wrapper);
    }

    public BankProduct getOneProduct(String id) {
        return bankProductMapper.selectById(id);
    }

    public List<BankProduct> getUnpassProduct() {
        QueryWrapper<BankProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 0);
        return bankProductMapper.selectList(wrapper);
    }

    public List<BankProduct> getProductList() {
        return bankProductMapper.selectList(null);
    }

    public List<BankProduct> getProductByFilter(String form, String business, String pool) {
        QueryWrapper<BankProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 1);
        if(!form.equals("all")) {
            wrapper.eq("form", form);
        }
        if(!business.equals("all")) {
            wrapper.eq("business", business);
            System.out.println(business);
        }
        if(!pool.equals("all")) {
            wrapper.eq("pool", pool);
        }
        return bankProductMapper.selectList(wrapper);
    }

    public int passProduct(String id) {
        BankProduct product = bankProductMapper.selectById(id);
        product.setStatus(1);
        return bankProductMapper.updateById(product);
    }
}
